package com.test.servlet;


import java.io.File;
import java.io.FileFilter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

public class DeleteTmpFiles extends HttpServlet
{

	public void destroy()
	{
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void init() throws ServletException
	{
//		//方法1
//		File file=new File(".");
//		File[] files=file.listFiles();
//		for (File f : files)
//		{
//			if (f.getName().endsWith(".xls"))
//			{
//				f.delete();
//			}
//		}
		
		//方法2
		File file=new File(".");
		File[] files=file.listFiles(new FileFilter(){

			public boolean accept(File pathname)
			{
				if (pathname.getName().endsWith(".xls"))
					{
					return true;
					}
				return false;
			}
			
		});
		for (File f : files)
		{
			f.delete();
		}
	}

}
